#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<algorithm>
using namespace std;
#define int long long
int n, sum[100010], summ[100010];
struct node 
{
	int a, b;
}x[100010];
bool cmp(node a, node b) 
{
	return a.b < b.b;
}
signed main() 
{
	scanf("%lld", &n);
	for (int i = 1;i <= n;i++) 
		scanf("%lld", &x[i].a);
	for (int i = 1;i <= n;i++) 
		scanf("%lld", &x[i].b);
	sort(x + 1, x + 1 + n, cmp);
	for (int i = 1;i <= n;i++) 
		sum[i] = sum[i - 1] + x[i].a * x[i].b;
	for (int i = n;i >= 1;i--) 
		summ[i] = summ[i + 1] + x[i].a;
	int q;
	scanf("%lld", &q);
	while (q--) 
	{
		int k;
		scanf("%lld", &k);
		int l = 0, r = n, ans = 0;
		while (l <= r) 
		{
			int mid = (l + r) / 2;
			if (x[mid].b >= k) 
				r = mid - 1;
			else 
				ans = mid, l = mid + 1;
		}
		printf("%lld\n", sum[ans] + summ[ans + 1] * k);
	}
	return 0;
}

